home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Applications / Text / Text Editors / Alpha 5.31 Folder / Tcl / SystemCode / misc.tcl < prev    next >
Encoding:
Text File  |  1993-01-30  |  4.1 KB  |  171 lines  |  [TEXT/ALFA]

  1. #===========================================================================
  2. # Information about a selection or window.
  3. #===========================================================================
  4. proc wordCount {} {
  5.     if {[set chars [expr {[selEnd] - [getPos]}]]} {
  6.         set lines [expr {[lindex [posToRowCol [selEnd]] 0] - [lindex [posToRowCol [getPos]] 0]}]
  7.         set text [getSelect]
  8.     } else {
  9.         set chars [maxPos]
  10.         set lines [lindex [posToRowCol $chars] 0]
  11.         set text [getText 0 [maxPos]]
  12.     }
  13.     if {[regsub -all {[!=;.,\(\):\{\"\}]} $text " " ret]} {
  14.         set words [llength $ret]
  15.     } else {
  16.         set words [llength $text]
  17.     }
  18.     alertnote [format "%d chars, %d words, %d lines" $chars $words $lines]
  19. }
  20.  
  21. proc matchingLines {} {
  22.     if [catch {prompt "Regular expression:" ""} reg] return
  23.     if {![string length $reg]} return
  24.     set reg ^.*$reg.*$
  25.     set pos [getPos]
  26.     set matches 0
  27.     while {![catch {search -f 1 -r 1 -m 0 -i 1 $reg $pos} mtch]} {
  28.         append lines "\r" [format "%4d: " [lindex [posToRowCol [lindex $mtch 0]] 0]] [eval getText $mtch]
  29.         set pos [lindex $mtch 1]
  30.         incr matches
  31.     }
  32.     new
  33.     insertText [format "%d matching lines\r-----" $matches] $lines "\r"
  34. }
  35.  
  36.  
  37. #=============================================================================
  38. # Random functions.
  39. #=============================================================================
  40. proc commentBox {} {
  41.     alertnote "I haven't gotten around to this yet." }
  42.  
  43. proc uncommentBox {} {
  44.         alertnote "I haven't gotten around to this yet." }
  45.  
  46. proc transposeWords {} {
  47.         forwardWord
  48.         setMark
  49.         backwardWord
  50.         cut
  51.         deleteChar
  52.         forwardWord
  53.         insertText "\ "
  54.         paste
  55. }
  56.  
  57. proc transposeChars {} {
  58.         setMark
  59.         forwardChar
  60.         cut
  61.         backwardChar
  62.         paste
  63.         forwardChar
  64. }
  65.  
  66. proc nextFunc {} {
  67.     searchFunc 1
  68. }
  69.  
  70. proc prevFunc {} {
  71.     searchFunc 0
  72. }
  73.  
  74. proc searchFunc {dir} {
  75.     global funcExpr
  76.     set pos [getPos]
  77.     select $pos
  78.     if ($dir==1) {
  79.         incr pos
  80.     } else {
  81.         set pos [expr $pos-1]
  82.     }
  83.     eval select [search -f $dir -i 1 -r 1 $funcExpr $pos]
  84. }
  85. bind Kpad1 prevFunc
  86. bind Kpad3 nextFunc
  87.  
  88. #===========================================================================
  89. # Include file manipulation. - called from Alpha.
  90. #===========================================================================
  91. proc openSelection {} {
  92.     global includePath
  93.     global Think
  94.     set path [substituteVars $includePath]
  95.     set fname [getSelect]
  96.     if {[string last ".h" $fname]=="-1"} {
  97.         set fname ${fname}.h
  98.     }
  99.     foreach dir $path {
  100.         if {[file exists $dir$fname]} {
  101.             edit $dir$fname
  102.             return
  103.         }
  104.     }
  105.     beep
  106. }
  107. #===========================================================================
  108. # Add temporary fileset.
  109. #===========================================================================
  110. proc addFileset {} {
  111.     global fileSets
  112.     global fileSetNames
  113.     global currFileSet
  114.     
  115.     set name [getline "New fileset name:" ""]
  116.     if {![string length $name]} return
  117.     
  118.     set dir [get_directory]
  119.     if {![string length $dir]} return
  120.     
  121.     set filePat [getline "File pattern:" "*"]
  122.     if {![string length $filePat]} return
  123.     
  124.     set newFSet [glob "$dir:$filePat"]
  125.     lappend fileSets [linsert $newFSet 0 $name]
  126.     lappend fileSetNames $name
  127.     addMenuItem -m fileSets $name
  128.     set currFileSet $name
  129. }
  130.  
  131.  
  132. proc getDirPath {} {
  133.     set str [getPathName]
  134.     set ind [string last ":" $str]
  135.     if {$ind != 0} {
  136.         set str [string range $str 0 [expr $ind-1]]
  137.     }
  138.     return $str
  139. }
  140.  
  141.  
  142. #===========================================================================
  143. # Comment routines.
  144. #===========================================================================
  145. proc commentPara {} {
  146. }
  147.  
  148.  
  149.  
  150. #===========================================================================
  151. # Sorting the selection.
  152. # AUTHOR: David C. Black     black@mpd.tandem.com
  153. #===========================================================================
  154. proc sortLines {} {
  155.     set start [getPos]
  156.     set end  [selEnd]
  157.     if {$start == $end} {
  158.         alertnote "You must highlight the section you wish to sort."
  159.         return
  160.     }
  161.     if {[lookAt [expr $end-1]] != "\r"} {
  162.         alertnote "The selection must consist only of complete lines."
  163.         return
  164.     }
  165.     set text [getText $start [expr {$end-1}]]
  166.     set text [join [lsort [split $text "\r"]] "\r"]
  167.     replaceText $start [expr {$end-1}] $text
  168.     select $start $end
  169. }
  170.  
  171.